import { login, getUserBaseInfo, getEmplyeeBaseInfo } from '@/api/user'
import { setToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    userInfo: {}
  },
  actions: {
    async userLogin({ commit }, data) {
      const res = await login(data)
      setToken(res)
    },
    logout({ commit }) {
      removeToken()
      commit('REMOVEUSERINFO')
    },
    async getUserInfo({ commit }) {
      const u = await getUserBaseInfo()
      const e = await getEmplyeeBaseInfo(u.userId)
      const o = { ...u, ...e }
      o.staffPhoto = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.2008php.com%2F09_Website_appreciate%2F10-07-11%2F1278861720_g.jpg&refer=http%3A%2F%2Fwww.2008php.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665888363&t=4e271d0fa4e6c807d38feffe28da8e6c'
      commit('GETUSERINFO', o)
    }
  },
  mutations: {
    GETUSERINFO(state, userInfo) {
      state.userInfo = userInfo
    },
    REMOVEUSERINFO(state) {
      state.userInfo = {}
    }
  },
  getters: {}
}
